﻿using Amazon.EC2;
using Amazon.EC2.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainalytics.StorageSnapshot.AWS
{
    class EbsVolume
    {
        static async Task<bool> CreateVolumeFromSnapshot(string snapshotId)
        {
            try
            {
                using (var ec2Client = new AmazonEC2Client(AwsCredentials.AwsAccessKey, AwsCredentials.AwsSecretKey))
                {
                    //var snapshotInProgress = await CheckIfSnapshotIsInProgress(volumeId);
                    //if (!snapshotInProgress)
                    {
                        var x = await ec2Client.CreateVolumeAsync(new CreateVolumeRequest
                        {
                            SnapshotId = snapshotId,
                            VolumeType = VolumeType.Gp2,
                            Encrypted = false,
                            AvailabilityZone = "eu-west-1b"
                        }, System.Threading.CancellationToken.None);
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
    }
}
